<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android,Note," />





  <link rel="alternate" href="/atom.xml" title="GrantonZhuang's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="Service 与 Activity 一样，是 Android 的四大组件之一，通常它的用途有两种。

一种是启动状态，放在后台运行，这里说是后台运行，实际上 Service 还是跑在 UI 线程 里的，所以如果要执行耗时间的任务，依旧需要开辟一个工作线程，那为什么还需要 Service 呢，直接开辟工作线程不就得了？个人看法，Service 是 Android 自身的组件，在系统内存吃紧的时候，">
<meta property="og:type" content="article">
<meta property="og:title" content="Service 的启动过程 启动状态">
<meta property="og:url" content="https://grantonzhuang.github.io/2016/08/07/SthAboutServiceLaunch/index.html">
<meta property="og:site_name" content="GrantonZhuang's Blog">
<meta property="og:description" content="Service 与 Activity 一样，是 Android 的四大组件之一，通常它的用途有两种。

一种是启动状态，放在后台运行，这里说是后台运行，实际上 Service 还是跑在 UI 线程 里的，所以如果要执行耗时间的任务，依旧需要开辟一个工作线程，那为什么还需要 Service 呢，直接开辟工作线程不就得了？个人看法，Service 是 Android 自身的组件，在系统内存吃紧的时候，">
<meta property="og:updated_time" content="2016-08-07T15:42:07.027Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Service 的启动过程 启动状态">
<meta name="twitter:description" content="Service 与 Activity 一样，是 Android 的四大组件之一，通常它的用途有两种。

一种是启动状态，放在后台运行，这里说是后台运行，实际上 Service 还是跑在 UI 线程 里的，所以如果要执行耗时间的任务，依旧需要开辟一个工作线程，那为什么还需要 Service 呢，直接开辟工作线程不就得了？个人看法，Service 是 Android 自身的组件，在系统内存吃紧的时候，">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="https://grantonzhuang.github.io/2016/08/07/SthAboutServiceLaunch/"/>

  <title> Service 的启动过程 启动状态 | GrantonZhuang's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">GrantonZhuang's Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Service 的启动过程 启动状态
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-08-07T10:06:39+08:00" content="2016-08-07">
              2016-08-07
            </time>
          </span>

          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>Service 与 Activity 一样，是 Android 的四大组件之一，通常它的用途有两种。</p>
<ul>
<li><p>一种是启动状态，放在后台运行，这里说是后台运行，实际上 Service 还是跑在 <strong>UI 线程</strong> 里的，所以如果要执行耗时间的任务，依旧需要开辟一个工作线程，那为什么还需要 Service 呢，直接开辟工作线程不就得了？个人看法，Service 是 Android 自身的组件，在系统内存吃紧的时候，Service 具有较高的优先级，是不那么容易被系统杀死的，所以用 Service 来执行后台任务是最 Android 的。</p>
</li>
<li><p>一种是绑定状态，作为进程间通信的服务端，和其他的客户端进程使用 AIDL 的方式进行交互。</p>
</li>
</ul>
<a id="more"></a>
<p>这篇文章是读书笔记，主要内容为 Service 的启动状态的执行过程.</p>
<h2 id="入口"><a href="#入口" class="headerlink" title="入口"></a>入口</h2><p>通常我们在 Activity，Application，Service 中，会以以下代码启动一个 Service</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">startService(<span class="keyword">new</span> Intent(<span class="keyword">this</span>, MyService.class));</div></pre></td></tr></table></figure>
<p>这时候调用的都是父类 ContextWrapper 的方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Override</span></div><div class="line"><span class="function"><span class="keyword">public</span> ComponentName <span class="title">startService</span><span class="params">(Intent service)</span> </span>&#123;</div><div class="line">    <span class="keyword">return</span> mBase.startService(service);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>Activity 创建的时候使用 attach() 方法将这个 mBase 变量与一个 <code>ContextImpl</code> 实例关联起来，下面是 ContextImpl 中 <code>startService()</code> 的实现.</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Override</span></div><div class="line"><span class="function"><span class="keyword">public</span> ComponentName <span class="title">startService</span><span class="params">(Intent service)</span> </span>&#123;</div><div class="line">    warnIfCallingFromSystemProcess();</div><div class="line">    <span class="keyword">return</span> startServiceCommon(service, mUser);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="AMS-的-startService"><a href="#AMS-的-startService" class="headerlink" title="AMS 的 startService"></a>AMS 的 startService</h2><p>startServiceCommon() 方法中，依旧是 <code>ActivityManagerNative.getDefault()</code> 也就是 <code>ActivityManagerService</code> 在执行 <code>startService</code> 方法，</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> ComponentName <span class="title">startServiceCommon</span><span class="params">(Intent service, UserHandle user)</span> </span>&#123;</div><div class="line">	<span class="comment">// ...</span></div><div class="line">    ComponentName cn = ActivityManagerNative.getDefault().startService(</div><div class="line">        mMainThread.getApplicationThread(), service, service.resolveTypeIfNeeded(</div><div class="line">                    getContentResolver()), getOpPackageName(), user.getIdentifier());</div><div class="line">	<span class="comment">// ...</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>再看 AMS 中的 <code>startService()</code> 方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Override</span></div><div class="line"><span class="function"><span class="keyword">public</span> ComponentName <span class="title">startService</span><span class="params">(IApplicationThread caller, Intent service,</span></span></div><div class="line">        String resolvedType, String callingPackage, <span class="keyword">int</span> userId)</div><div class="line">        <span class="keyword">throws</span> TransactionTooLargeException &#123;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">    <span class="keyword">synchronized</span>(<span class="keyword">this</span>) &#123;</div><div class="line">        <span class="comment">// ...</span></div><div class="line">        ComponentName res = mServices.startServiceLocked(caller, service,</div><div class="line">                resolvedType, callingPid, callingUid, callingPackage, userId);</div><div class="line">        Binder.restoreCallingIdentity(origId);</div><div class="line">        <span class="keyword">return</span> res;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这里调用了 <code>mServices.startServiceLocked()</code>, 与 Activity 的启动类似，AMS 中持有一个 <code>ActiveServices</code> 类型的实例来管理所有的 Service, 经过一系列的方法调用，最后交给 <code>ApplicationThread</code> 接管.</p>
<ul>
<li><code>ActiveServices#startServiceLocked()</code></li>
<li><code>ActiveServices#startServiceInnerLocked()</code></li>
<li><code>ActiveServices#bringUpServiceLocked()</code></li>
<li><code>ActiveServices#realStartServiceLocked()</code></li>
<li><code>app.thread.scheduleCreateService()</code> 这里调用了 <code>Service#onCreate()</code></li>
<li><code>ActiveService#sendServiceArgsLocked</code> 这里调用了 <code>Service</code> 的其他方法，如 <code>onStartCommand()</code></li>
</ul>
<h2 id="ApplicationThread"><a href="#ApplicationThread" class="headerlink" title="ApplicationThread"></a>ApplicationThread</h2><h3 id="scheduleCreateService"><a href="#scheduleCreateService" class="headerlink" title="scheduleCreateService"></a>scheduleCreateService</h3><blockquote>
<p><code>app.thread</code> 成员变量同样是 <code>IApplicationThread</code> 接口的实现 <code>ApplicationThread</code> 的实例。</p>
</blockquote>
<p><code>ApplicationThread#scheduleCreateService()</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">scheduleCreateService</span><span class="params">(IBinder token,</span></span></div><div class="line">        ServiceInfo info, CompatibilityInfo compatInfo, <span class="keyword">int</span> processState) &#123;</div><div class="line">    updateProcessState(processState, <span class="keyword">false</span>);</div><div class="line">    CreateServiceData s = <span class="keyword">new</span> CreateServiceData();</div><div class="line">    s.token = token;</div><div class="line">    s.info = info;</div><div class="line">    s.compatInfo = compatInfo;</div><div class="line"></div><div class="line">    sendMessage(H.CREATE_SERVICE, s);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>与 Activity 一样，使用 Handler 的子类 H 来处理创建的过程</p>
<p><code>H#handleMessage()</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">case</span> CREATE_SERVICE:</div><div class="line">    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, <span class="string">"serviceCreate"</span>);</div><div class="line">    handleCreateService((CreateServiceData)msg.obj);</div><div class="line">    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);</div><div class="line">    <span class="keyword">break</span>;</div></pre></td></tr></table></figure>
<p>再调用回 <code>ApplicationThread</code> 自身的 <code>handleCreateService()</code> 方法。</p>
<p><code>ApplicationThread#handleCreateService()</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">handleCreateService</span><span class="params">(CreateServiceData data)</span> </span>&#123;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">    <span class="comment">// 使用 ClassLoader 加载 Service</span></div><div class="line">    java.lang.ClassLoader cl = packageInfo.getClassLoader();</div><div class="line">    service = (Service) cl.loadClass(data.info.name).newInstance();</div><div class="line">	<span class="comment">// ...</span></div><div class="line">    <span class="comment">// 绑定 Context 和 Service</span></div><div class="line">    ContextImpl context = ContextImpl.createAppContext(<span class="keyword">this</span>, packageInfo);</div><div class="line">    context.setOuterContext(service);</div><div class="line">    Application app = packageInfo.makeApplication(<span class="keyword">false</span>, mInstrumentation);</div><div class="line">    service.attach(context, <span class="keyword">this</span>, data.info.name, data.token, app,</div><div class="line">            ActivityManagerNative.getDefault());</div><div class="line">    <span class="comment">// 调用 onCreate 方法</span></div><div class="line">    service.onCreate();</div><div class="line">    <span class="comment">// 存储进 ArrayMap 中</span></div><div class="line">    mServices.put(data.token, service);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>经过这个方法以后，Service 已经被创建成功, <code>ActiveService</code> 继续调用 <code>sendServiceArgsLocked()</code> 方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">sendServiceArgsLocked</span><span class="params">(ServiceRecord r, <span class="keyword">boolean</span> execInFg,</span></span></div><div class="line">        <span class="keyword">boolean</span> oomAdjusted) <span class="keyword">throws</span> TransactionTooLargeException &#123;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">    r.app.thread.scheduleServiceArgs(r, si.taskRemoved, si.id, flags, si.intent);</div><div class="line">    <span class="comment">// ...</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="scheduleServiceArgs"><a href="#scheduleServiceArgs" class="headerlink" title="scheduleServiceArgs"></a>scheduleServiceArgs</h3><blockquote>
<p>这里同样是 <code>IApplicationThread</code> 的实现 <code>ApplicationThread</code> 来处理</p>
</blockquote>
<p><code>ApplicationThread#scheduleServiceArgs</code></p>
<p>同样是交给 Handler 的子类 H 爱处理</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">scheduleServiceArgs</span><span class="params">(IBinder token, <span class="keyword">boolean</span> taskRemoved, <span class="keyword">int</span> startId,</span></span></div><div class="line">    <span class="keyword">int</span> flags ,Intent args) &#123;</div><div class="line">    ServiceArgsData s = <span class="keyword">new</span> ServiceArgsData();</div><div class="line">    <span class="comment">// ...</span></div><div class="line"></div><div class="line">    sendMessage(H.SERVICE_ARGS, s);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><code>H#handleMessage()</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">case</span> SERVICE_ARGS:</div><div class="line">    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, <span class="string">"serviceStart"</span>);</div><div class="line">    handleServiceArgs((ServiceArgsData)msg.obj);</div><div class="line">    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);</div><div class="line">    <span class="keyword">break</span>;</div></pre></td></tr></table></figure>
<p>再调用回 <code>ApplicationThread</code> 自身的 <code>handleServiceArgs</code> 方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">handleServiceArgs</span><span class="params">(ServiceArgsData data)</span> </span>&#123;</div><div class="line">    <span class="comment">// 从 ArrayMap 中找到对应的 Service</span></div><div class="line">    Service s = mServices.get(data.token);</div><div class="line">    <span class="keyword">if</span> (s != <span class="keyword">null</span>) &#123;</div><div class="line">        <span class="comment">// ...</span></div><div class="line">        <span class="keyword">if</span> (data.args != <span class="keyword">null</span>) &#123;</div><div class="line">            data.args.setExtrasClassLoader(s.getClassLoader());</div><div class="line">            data.args.prepareToEnterProcess();</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">int</span> res;</div><div class="line">        <span class="keyword">if</span> (!data.taskRemoved) &#123;</div><div class="line">            <span class="comment">// 调用 onStartCommand 方法</span></div><div class="line">            res = s.onStartCommand(data.args, data.flags, data.startId);</div><div class="line">        &#125; <span class="keyword">else</span> &#123;</div><div class="line">            s.onTaskRemoved(data.args);</div><div class="line">            res = Service.START_TASK_REMOVED_COMPLETE;</div><div class="line">        &#125;</div><div class="line">        <span class="comment">// ...</span></div><div class="line">    &#125;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag">#Android</a>
          
            <a href="/tags/Note/" rel="tag">#Note</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/08/04/SthAboutActivityLaunch/" rel="next" title="Activity 的启动过程">
                <i class="fa fa-chevron-left"></i> Activity 的启动过程
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/08/10/SthAboutServiceLaunch2/" rel="prev" title="Service 的启动过程 绑定状态">
                Service 的启动过程 绑定状态 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://ww1.sinaimg.cn/mw690/6e8939a6gw1f3g1u1mc6lj20hs0hsmxf.jpg"
               alt="Granton Zhuang" />
          <p class="site-author-name" itemprop="name">Granton Zhuang</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives/index.html">
              <span class="site-state-item-count">26</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#入口"><span class="nav-number">1.</span> <span class="nav-text">入口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#AMS-的-startService"><span class="nav-number">2.</span> <span class="nav-text">AMS 的 startService</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ApplicationThread"><span class="nav-number">3.</span> <span class="nav-text">ApplicationThread</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#scheduleCreateService"><span class="nav-number">3.1.</span> <span class="nav-text">scheduleCreateService</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#scheduleServiceArgs"><span class="nav-number">3.2.</span> <span class="nav-text">scheduleServiceArgs</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Granton Zhuang</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  

  

  

</body>
</html>
